import 'dart:math';

import 'package:intl/intl.dart';

/// Formats the input number in simple currency format.
/// Example: If [name] = 'CNY', then '￥' will be added in front of the output.
String formatNumber(dynamic number, {String name = '', int? decimalDigits}) {
  return NumberFormat.simpleCurrency(
    name: name,
    decimalDigits: decimalDigits,
  ).format(number ?? 0);
}

/// Formats the expense number, adds '-' prefix if zero.
String formatExpenseNumber(
  dynamic number, {
  String name = '',
  int? decimalDigits,
}) {
  return (number == 0 ? '-' : '') +
      formatNumber(number, name: name, decimalDigits: decimalDigits);
}

/// Formats the balance number, adds '+' prefix if positive.
String formatBalanceNumber(
  dynamic number, {
  String name = '',
  int? decimalDigits,
}) {
  return (number >= 0 ? '+' : '') +
      formatNumber(number, name: name, decimalDigits: decimalDigits);
}

/// Generates random integer between [min] and [max].
int generateRandomIntBetweenRange(int min, int max) {
  return min + (max - min == 0 ? 0 : (Random().nextInt(max - min)));
}
